﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BLL;
using IBLL;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Model;

namespace MedicalSystem.Controllers
{
    public class PatientController : Controller
    {
        private readonly ILogger<PatientController> _logger;
        IPatientBLL _bll;

        public PatientController(ILogger<PatientController> logger, IPatientBLL bll)
        {
            _logger = logger;
            _bll = bll;
        }
        //患者查询视图
        public IActionResult ShowPatient()
        {
            return View();
        }
        //患者详情
        public IActionResult UpdatePatient()
        {
            return View();

        }
        //添加患者
        public IActionResult AddPatients()
        {
            return View();
        }
        /// <summary
        /// >
        /// 查询患者信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetPatient(string name, int pageIndex = 1, int pageSize = 10)
        {
            var list = _bll.GetPatient(name, pageIndex, pageSize);

            return Json(list);
        }
        /// <summary>
        /// 新增患者信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult AddPatient(Patient model)
        {
            return Json(_bll.AddPatient(model));
        }
        /// <summary>
        /// 查询科室信息（下拉框绑定）
        /// </summary>
        /// <returns></returns>
        public JsonResult GetOutpatient()
        {
            return Json(_bll.GetOutpatient());
        }
        /// <summary>
        /// 根据id查询单条数据（编辑详情）
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public JsonResult GetPatientById(int pid)
        {
            return Json(_bll.GetPatientById(pid));
        }
        /// <summary>
        /// 修改患者信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult Updatepat(Patient model)
        {
            return Json(_bll.UpdatePatient(model));
        }
    }
}
